#include "signalpopmenu.h"
#include "ui_signalpopmenu.h"

SignalPopMenu::SignalPopMenu(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SignalPopMenu)
{
    ui->setupUi(this);
}

SignalPopMenu::~SignalPopMenu()
{
    delete ui;
}

void SignalPopMenu::on_Btn_Close_clicked()
{
    this->hide();
}

void SignalPopMenu::on_Btn_ATC_EB_Test_clicked()
{
    PopupDialog *dialog = new PopupDialog();
    dialog->move(parentWidget()->x()+(parentWidget()->width()-dialog->width())/2,
                 parentWidget()->y()+parentWidget()->parentWidget()->y()+(parentWidget()->height()-dialog->height())/2);
    dialog->setPopupText("确认进行紧急制动测试吗?");
    if(dialog->exec() == 1)
    {
        emit signal_atc_test(ATC_TEST_EB);
    }
}

void SignalPopMenu::on_Btn_ATC_BroadCast_Test_clicked()
{
    PopupDialog *dialog = new PopupDialog();
    dialog->move(parentWidget()->x()+(parentWidget()->width()-dialog->width())/2,
                 parentWidget()->y()+parentWidget()->parentWidget()->y()+(parentWidget()->height()-dialog->height())/2);
    dialog->setPopupText("确认进行广播测试吗?");
    if(dialog->exec() == 1)
    {
        emit signal_atc_test(ATC_TEST_BROAD);
    }
}

void SignalPopMenu::on_Btn_ATC_RCS_Test_clicked()
{
    PopupDialog *dialog = new PopupDialog();
    dialog->move(parentWidget()->x()+(parentWidget()->width()-dialog->width())/2,
                 parentWidget()->y()+parentWidget()->parentWidget()->y()+(parentWidget()->height()-dialog->height())/2);
    dialog->setPopupText("确认进行RCS测试吗?");
    if(dialog->exec() == 1)
    {
        emit signal_atc_test(ATC_TEST_RCS);
    }
}

void SignalPopMenu::set_RCS_Test_Stat(uint8_t stat)
{
    ui->Red_Wlan_Stat_Text->setText("");
    ui->Blue_Wlan_Stat_Text->setText("");
    ui->Red_Wlan_Stat->setStyleSheet("background-color: rgb(0, 0, 0);");
    ui->Blue_Wlan_Stat->setStyleSheet("background-color: rgb(0, 0, 0);");
    if(stat == 1)
    {
        ui->Red_Wlan_Stat_Text->setText("RCS自检进行中");
        ui->Blue_Wlan_Stat_Text->setText("RCS自检进行中");
    }
    else if(stat == 2)
    {
        ui->Red_Wlan_Stat->setStyleSheet("border-image: url(:/Images/SIGNAL/RadioFine.png);");
        ui->Blue_Wlan_Stat->setStyleSheet("border-image: url(:/Images/SIGNAL/RadioFine.png);");
    }
    else if(stat == 3)
    {
        ui->Red_Wlan_Stat->setStyleSheet("border-image: url(:/Images/SIGNAL/RadioFaulty.png);");
        ui->Blue_Wlan_Stat->setStyleSheet("border-image: url(:/Images/SIGNAL/RadioFaulty.png);");
    }
    else if(stat == 4)
    {
        ui->Red_Wlan_Stat->setStyleSheet("border-image: url(:/Images/SIGNAL/RadioFine.png);");
        ui->Blue_Wlan_Stat->setStyleSheet("border-image: url(:/Images/SIGNAL/RadioFaulty.png);");
    }
    else if(stat == 5)
    {
        ui->Red_Wlan_Stat->setStyleSheet("border-image: url(:/Images/SIGNAL/RadioFaulty.png);");
        ui->Blue_Wlan_Stat->setStyleSheet("border-image: url(:/Images/SIGNAL/RadioFine.png);");
    }
    else if(stat == 254)
    {
        ui->Red_Wlan_Stat_Text->setText("非RM模式，不能进行RCS测试自检");
        ui->Blue_Wlan_Stat_Text->setText("非RM模式，不能进行RCS测试自检");
    }
    else
    {
        ui->Red_Wlan_Stat_Text->setText("");
        ui->Blue_Wlan_Stat_Text->setText("");
        ui->Red_Wlan_Stat->setStyleSheet("background-color: rgb(0, 0, 0);");
        ui->Blue_Wlan_Stat->setStyleSheet("background-color: rgb(0, 0, 0);");
    }
}

void SignalPopMenu::set_EB_Test_Stat(uint8_t stat)
{
    if(stat == 0xF2)
        ui->eb_test_stat->setText(QString("请手动进行紧急测试！"));
    else if(stat == 0xF0)
        ui->eb_test_stat->setText(QString("紧急测试失败！请再次测试"));
    else if(stat == 0xF1)
        ui->eb_test_stat->setText(QString("紧急制动测试成功！"));
    else if(stat == 0x01)
        ui->eb_test_stat->setText(QString("紧急制动1施加2缓解"));
    else if(stat == 0x02)
        ui->eb_test_stat->setText(QString("紧急制动1缓解2施加"));
    else if(stat == 0x03)
        ui->eb_test_stat->setText(QString("紧急制动1施加2施加"));
    else if(stat == 0x04)
        ui->eb_test_stat->setText(QString("紧急制动1缓解2缓解"));
}
